package com.stary.code.springboot.config.data;

import org.apache.commons.lang.StringUtils;

import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.stary.code.springboot.rules.DataSourcePoolType;
import com.stary.mybatisplus.generator.config.DbDriverName;

/**
 * <p>datasource 配置类</p>
 * @author stary {@link stary1993@qq.com}
 * @since 2018-7-4
 */
public class DataSourceConfig {
	
	/**
	 * url
	 */
	private String url;
	/**
	 * 类型，默认oracle
	 */
	private DbType type = DbType.ORACLE;
	/**
	 * 驱动类名，根据类型自动匹配
	 */
	private String driver;
	/**
	 * 登录用户
	 */
	private String username;
	/**
	 * 登录密码
	 */
	private String password;	
	/**
	 * 连接池类型，默认 HikariCP
	 */
	private DataSourcePoolType poolType = DataSourcePoolType.HIKARICP;

	public String getUrl() {
		return url;
	}
	public DataSourceConfig setUrl(String url) {
		this.url = url;
		return this;
	}
	public DbType getType() {
		return type;
	}
	public DataSourceConfig setType(DbType type) {
		this.type = type;
		return this;
	}
	public String getDriver() {
		if (StringUtils.isEmpty(driver)) {
			switch (type) {
			case MYSQL:
				driver = DbDriverName.MYSQL.getName();
				break;
			case SQL_SERVER:
				driver = DbDriverName.SQLSERVER.getName();
				break;
			default:
				driver = DbDriverName.ORACLE.getName();
				break;
			}
		}
		return driver;
	}
	public DataSourceConfig setDriver(String driver) {
		this.driver = driver;
		return this;
	}
	public String getUsername() {
		return username;
	}
	public DataSourceConfig setUsername(String username) {
		this.username = username;
		return this;
	}
	public String getPassword() {
		return password;
	}
	public DataSourceConfig setPassword(String password) {
		this.password = password;
		return this;
	}
	public DataSourcePoolType getPoolType() {
		return poolType;
	}
	public DataSourceConfig setPoolType(DataSourcePoolType poolType) {
		this.poolType = poolType;
		return this;
	}

}
